<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${tabTitle}</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<div id="pageInTab" class="pageInTab">
				<form id="ins_cfg_info_edit_form">
					<div class="fieldset1 tabel_col clearFix">
						<div class="fieldBox col_33">
							<div class="label">机构名称</div>
							<div class="field">
								<span name="fundRasInsNm" id="fundRasInsNm">${fundRasInsNm}</span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">客户名称</div>
							<div class="field">
								<span >${cstNm}</span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">身份证号码</div>
							<div class="field">
								<span >${certNo}</span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">开户银行</div>
							<div class="field">
                                <select name="bkNo" id="bkNo" value="${bkNo}" validate="{required:true}">
	                                <c:if test="${bkNo == null || bkNo == ''}">
	                                	<option value="" selected="selected">--请选择--</option>
	                                </c:if>
	                                <c:if test="${bkNo != null && bkNo != ''}">
	                                	<option value="">--请选择--</option>
	                                </c:if>
                                    <c:forEach items="${bankList}" var="item">
                                    	<c:if test="${item.key == bkNo}">
                                        	<option value="${item.key}" selected="selected">${item.value}</option>
                                    	</c:if>
                                    	<c:if test="${item.key != bkNo}">
                                        	<option value="${item.key}">${item.value}</option>
                                    	</c:if>
                                    </c:forEach>
                                </select>
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">银行账号</div>
							<div class="field">
								<input name="accNo" id="accNo" type="text" class="ui-textbox" value="${accNo}" validate="{number:true, maxlength:22, minlength:15}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">预留手机号</div>
							<div class="field">
								<input name="mp" id="mp" type="text" class="ui-textbox" value="${mp}" validate="{number:true, maxlength:11, minlength:11}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">月收入</div>
							<div class="field">
								<input name="monIncmYuan" id="monIncmYuan" type="text" class="ui-textbox" value="${monIncmYuan}" validate="{number:true, maxlength:11, minlength:4}">
								<span class="requiredSymbol">*</span>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">浦发开户状态</div>
							<div class="field">
								<input name="thdaccsts" id="thdaccsts" readonly= "true" type="text" class="ui-textbox" value="${thdaccsts}">
								<%--<span class="requiredSymbol">*</span>--%>
							</div>
						</div>
						<div class="fieldBox col_66">
							<div class="label">开户失败</div>
							<div class="field">
								<textarea name="thdaccrem" id="thdaccrem" readonly="true" rows="5" class="l-textarea" style="width:80%" value="" ></textarea>
								<input name="thdaccrems" id="thdaccrems" type="hidden" value="${thdaccrem}">
								<%--<span class="requiredSymbol">*</span>--%>
							</div>
						</div>
						<!-- hide data -->
						<div class="fieldBox col_100" style="display: none;">
							<div class="field">
								<input name="prjId" id="prjId" type="text" class="ui-textbox" value="${prjId}">
								<input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
								<input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="${cstNm}">
								<input name="certNo" id="certNo" type="text" class="ui-textbox" value="${certNo}">
								<input name="cstAccInfoId" id="cstAccInfoId" type="text" class="ui-textbox" value="${cstAccInfoId}">
								<input name="verifyCode" id=verifyCode type="text" class="ui-textbox" value="${verifyCode}">
								<input name="fundRasInsId" id=fundRasInsId type="text" class="ui-textbox" value="${fundRasInsId}">
								<input name="uploadFileSucc" id=uploadFileSucc type="text" class="ui-textbox" value="${uploadFileSucc==null?'false':uploadFileSucc}">
								<input name="createAccountSucc" id=createAccountSucc type="text" class="ui-textbox" value="${createAccountSucc==null?'false':createAccountSucc}">
								<input name="confirmFile" id=confirmFile type="text" class="ui-textbox" value="0">
							</div>
						</div>
					</div>
	                <div id="saveInsCfgDiv" class="btnsBox">
	                    <sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjBscInfo" pInstId="${pInstId}">
	                        <span id="saveInsCfg" class="sq-button sq-button-round disabled" onclick="return save();">获取验证码</span>
	                    </sys:FlowFrmAth>

                	</div>
					<!-- REQ-7008 pc保存月收入 pc端不进行保存开户操作 先不改动原接口 增加 -->
					<div id="saveInsCfgDivInfo" class="btnsBox">
						<sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjBscInfo" pInstId="${pInstId}">
							<span id="saveInsCfgInfo" class="sq-button sq-button-round" onclick="return saveInfo();">保存</span>
						</sys:FlowFrmAth>
					</div>
					<div id="hintInfo" style="text-align: center">
						<span style="color: red">友情提示：浦发开户操作请移至狮桥在线操作，本页面仅支持修改月收入</span>
					</div>
					<div id="hint" style="text-align: center">
						<span style="color: red">友情提示：浦发开户操作请移至狮桥在线操作</span>
					</div>
				</form>
			</div>
		</div>
		<div id="inputVerifyCodediv" style="display:none">
			<form id="in_verify_code_form">
				<div class="fieldset1 tabel_col clearFix">
				    <div class="fieldBox col_100">
		                短信已发送至<span id='cerifyCodeDivMp'></span>，请联系客户获取验证码，该验证码10分钟内有效！
		            </div>
		            <div class="fieldBox col_90" style="width:100%;">
		                <div class="label">验证码</div>
		                <div class="field">
							<table>
								<tr>
									<td><input name="inVerifyCode" id="inVerifyCode" type="text" class="ui-textbox" value="" validate="{required:true,maxlength:30}"></td>
									<td><span class="requiredSymbol">&nbsp;*</span></td>
								</tr>
							</table>
						</div>
		            </div>
	            </div>
            </form>
		</div>
	</div>

<script type="text/javascript">

var detailFlag = '${detailFlag}';
// REQ-7008 信审初审节点 客户经理 可修改字段
var fromCAFlag = '${fromCAFlag}';
var fromCMFlag = '${fromCMFlag}';

$(function () {
	initData();
});

function initData() {
    $("#ins_cfg_info_edit_form").ligerForm({
        validate: true
    });
    $("#in_verify_code_form").ligerForm({
        validate: true
    });
    $("#thdaccrem").val($("#thdaccrems").val());
	disabledInput();
	enableFields();
}

function disabledInput() {
	if(detailFlag == "true" || $("#createAccountSucc").val() == "true") {
	    // 项目详情
		liger.get("bkNo").setDisabled();
		liger.get("accNo").setDisabled();
		liger.get("mp").setDisabled();
		liger.get("monIncmYuan").setDisabled();
		$("#saveInsCfgDiv").hide();
        $("#hint").hide();
	}else{
	    // 项目修改
        // $("#hint").show();
	}
	if (detailFlag == "true") {
		$("#saveInsCfgDivInfo").hide();
		$("#hintInfo").hide();
	}
}

function enableFields() {
	if (null != fromCAFlag && "true" == fromCAFlag) {
		liger.get("bkNo").setDisabled();
		liger.get("accNo").setDisabled();
		liger.get("mp").setDisabled();
		liger.get("monIncmYuan").setEnabled();
		$("#saveInsCfgDiv").hide();
		$("#saveInsCfgDivInfo").show();
		$("#hintInfo").show();
		$("#hint").hide();
	}
	if (null != fromCMFlag && "true" == fromCMFlag) {
		liger.get("bkNo").setDisabled();
		liger.get("accNo").setDisabled();
		liger.get("mp").setDisabled();
		liger.get("monIncmYuan").setEnabled();
		$("#saveInsCfgDiv").hide();
		$("#saveInsCfgDivInfo").show();
		$("#hintInfo").show();
		$("#hint").hide();
	}
}

// REQ-7008 只保存月收入
function saveInfo() {
	if ($("#saveInsCfgInfo").attr("class").indexOf("disabled") > 0) {
		return;
	}

	if(!$("#monIncmYuan").val()){
		top.$.ligerDialog.SQalert({content: "请填写月收入！", SQ_type: "error"});
		return false;
	}
	var data = {};
	data["monIncmYuan"] = $("#monIncmYuan").val();
	data["prjId"] = $("#prjId").val();
	data["cstId"] = $("#cstId").val();
	data["cstNm"] = $("#cstNm").val();
	data["fundRasInsId"] = $("#fundRasInsId").val();

	var url = '<%=path%>/institution/spdbank/saveInfo.do';
	var wait_dialog;
	$.ajax({
		type: 'post',
		dataType: 'json',
		data: data,
		url: url,
		beforeSend: function () {
			wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
		},
		success: function (msg) {
			wait_dialog.close();
			if (msg.success == 1) {
				UIUtils.alertSuccessHold1(msg.info);
			} else {
				UIUtils.alertErrorHold1(msg.info);
			}
		}
	});
}

// 保存项目客户信息，后面弹出准入验证的资料确认页
function save() {
    if ($("#saveInsCfg").attr("class").indexOf("disabled") > 0) {
        return;
    }

	var ligerForm = liger.get("ins_cfg_info_edit_form");
    if (!ligerForm.valid()) {
        top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
        return false; //验证不通过，不执行以下代码
    }
    var data = ligerForm.getData();
    if(!$("#bkNo").val()){
        top.$.ligerDialog.SQalert({content: "请选择开户银行！", SQ_type: "error"});
        return false;
    }
    if(!$("#accNo").val()){
        top.$.ligerDialog.SQalert({content: "请填写银行账号！", SQ_type: "error"});
        return false;
    }
    if(!$("#mp").val()){
        top.$.ligerDialog.SQalert({content: "请填写预留手机号码！", SQ_type: "error"});
        return false;
    }
    if(!$("#monIncmYuan").val()){
        top.$.ligerDialog.SQalert({content: "请填写月收入！", SQ_type: "error"});
        return false;
    }
    data["bkNo"] = liger.get("bkNo").selectedValue;
    data["bkNm"] = liger.get("bkNo").selectedText;
    data["accNo"] =  $("#accNo").val();
    data["mp"] = $("#mp").val();
    data["monIncmYuan"] = $("#monIncmYuan").val();
    data["prjId"] = $("#prjId").val();
    data["cstId"] = $("#cstId").val();
    data["cstNm"] = $("#cstNm").val();
    data["fundRasInsId"] = $("#fundRasInsId").val();

    var url = '<%=path%>/institution/spdbank/save.do';
    var wait_dialog;
    $.ajax({
        type: 'post',
        dataType: 'json',
        data: data,
        url: url,
        beforeSend: function () {
            wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        },
        success: function (msg) {
            wait_dialog.close();
            if (msg.success == 1) {
            	if($("#uploadFileSucc").val() == "true") {
            		getVerifyCode();
            	}
            	else {
            		toConfirmFileForCreditPage();
            	}
            } else {
                UIUtils.alertErrorHold1(msg.info);
            }
        }
    });
}

// 弹窗 确认身份证正反面图片文件
function toConfirmFileForCreditPage() {
    var onConfirm = function (item, dialog) {
        dialog.hide();
        submitCredit(); // 准入验证
    };
    var onCancel = function (item, dialog) {
        dialog.hide();
    };
    $.ligerDialog.SQopen({
        width: 400,
        //height: 300,
        autoFixHeight: true,
        title : '准入验证 请确认身份证信息',
        url: "<%=path%>/institution/spdbank/toConfirmFileForCreditPage.do?prjId=${prjId}",
        buttons: [
        	{text: "开户并获取验证码", onclick: onConfirm, type: 'confirm'},
            {text: "取消", onclick: onCancel, type: 'cancel'}
        ]
    });
}

// 准入验证
function submitCredit() {
	var ligerForm = liger.get("ins_cfg_info_edit_form");
	if($("#confirmFile").val() != '1') {
		UIUtils.alertErrorHold1("请补充或修改项目资料“身份证正面”和“身份证反面”后再操作！");
		return;
	}
	var data = ligerForm.getData();
	data["prjId"] = $("#prjId").val();
	data["cstId"] = $("#cstId").val();
	data["fundRasInsId"] = $("#fundRasInsId").val();
    var url = '<%=path%>/institution/spdbank/submitCredit.do';
    var wait_dialog;
    $.ajax({
        type: 'post',
        dataType: 'json',
        data: data,
        url: url,
        beforeSend: function () {
            wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        },
        success: function (msg) {
            wait_dialog.close();
            if (msg.success == 1) {
            	getVerifyCode(); // 提交资料、获取验证码
            } else {
                UIUtils.alertErrorHold1(msg.info);
            }
        }
    });
}

// 提交资料、获取验证码
function getVerifyCode() {
	var ligerForm = liger.get("ins_cfg_info_edit_form");
	var data = ligerForm.getData();
	data["prjId"] = $("#prjId").val();
	data["cstId"] = $("#cstId").val();
	data["fundRasInsId"] = $("#fundRasInsId").val();
    var url = '<%=path%>/institution/spdbank/getVerifyCode.do';
    var wait_dialog;
    $.ajax({
        type: 'post',
        dataType: 'json',
        data: data,
        url: url,
        beforeSend: function () {
            wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        },
        success: function (msg) {
            wait_dialog.close();
            if (msg.success == 1) {
            	toConfirmVerifyCodePage(); // 弹窗 开户申请输入验证码
            } else {
                UIUtils.alertErrorHold1(msg.info);
            }
            if($("#uploadFileSucc").val() == "false" && msg.data.uploadFileSucc == "true") {
            	$("#uploadFileSucc").val("true");
            }
        }
    });
}

// 弹窗 开户申请输入验证码
function toConfirmVerifyCodePage() {
	var _dialog;
	$("#cerifyCodeDivMp").text($("#mp").val());
	var onConfirm = function (item, dialog) {
		var verifyCodeForm = liger.get("in_verify_code_form");
	    if (!verifyCodeForm.valid()) {
	        top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
	        return false; //验证不通过，不执行以下代码
	    }
	    // alert($("#inVerifyCode").val());
		_dialog.hide();
		createAccount($("#inVerifyCode").val());
	};
	var onCancel = function (item, dialog) {
    	_dialog.hide();
	};
	_dialog = $.ligerDialog.open({
 		target: $("#inputVerifyCodediv"),
	    width: 500,
	    height: 150,
	    isResize: true,
	    modal: true,
	    title : '开户申请输入验证码',
	    buttons: [
          	{text: "校验", onclick: onConfirm, type: 'confirm'},
            {text: "取消", onclick: onCancel, type: 'cancel'}
	    ]
	});
}

// 提交用户输入的验证码进行开户
function createAccount(inVerifyCode) {
	var ligerForm = liger.get("ins_cfg_info_edit_form");
	var data = ligerForm.getData();
	data["prjId"] = $("#prjId").val();
	data["cstId"] = $("#cstId").val();
	data["verifyCode"] = inVerifyCode;
	data["fundRasInsId"] = $("#fundRasInsId").val();
	var url = '<%=path%>/institution/spdbank/createAccount.do';
	var wait_dialog;
	$.ajax({
	    type: 'post',
	    dataType: 'json',
	    data: data,
	    url: url,
	    beforeSend: function () {
	        wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
	    },
	    success: function (msg) {
	        wait_dialog.close();
	        if (msg.success == 1) {
            	$("#createAccountSucc").val("true");
            	disabledInput();
				UIUtils.alertSuccessHold1(msg.info);
	        } else {
				UIUtils.alertErrorHold1(msg.info);
	        }
	    }
	});
}

</script>

</body>
</html>